2016-05-05
Libraries in R are loaded in order:
.libPaths()## [1] "/usr/local/lib/R/site-library" "/usr/lib/R/site-library"
## [3] "/usr/lib/R/library"
You can also add an additional library path:
.libPaths(c("your/library/path", .libPaths()))Sometime you may need to execute your R script periodically and automatically:
Environment variable of R and RScript will be exported in this way.
Rscript <PATH OF YOUR R SCRIPT> <ARG1> <ARG2> ...If you use Linux or Mac, you can execute a R script directly with shebang and permission of execution.
#!/usr/bin/env RscriptAdd permission of execution:
chmod u+x schedualing/now.RCheck permission:
ls -l schedualing/now.R## -rwxrw-rw- 1 mansun mansun 1164 May 5 01:24 schedualing/now.R
Let’s try to pass some arguments to schedualing/now.R:
Get help:
schedualing/now.R -hPass a positional argument:
schedualing/now.R MansunAdd a flag -c:
schedualing/now.R Mansun -cAdd a optional argument:
schedualing/now.R Mansun -c -g "How are you?"Maintain crontab files to execute scheduled commands in Unix-like OS for individual users.
crontab [-u user] file
crontab [ -u user ] [ -i ] { -e | -l | -r }
-e (edit user's crontab)
-l (list user's crontab)
-r (delete user's crontab)
-i (prompt before deleting user's crontab)
you may need to use some command line editor like vim when using crontab -e to edit your crontab.
cd; mkdir github; cd github;* * * * * cd /home/mansun/github/BeyondBasicR/schedualing; ./now.R Mansuncrontab -l## * * * * * cd /home/mansun/github/BeyondBasicR/schedualing; ./now.R Mansun
┌───────────── min (0 - 59)
│ ┌────────────── hour (0 - 23)
│ │ ┌─────────────── day of month (1 - 31)
│ │ │ ┌──────────────── month (1 - 12)
│ │ │ │ ┌───────────────── day of week (0 - 6) (0 to 6 are Sunday to Saturday)
│ │ │ │ │
│ │ │ │ │
* * * * * command to execute
| mpg | cyl | disp | hp | |
|---|---|---|---|---|
| Mazda RX4 | 21 | 6 | 160 | 110 |
| Mazda RX4 Wag | 21 | 6 | 160 | 110 |
| Datsun 710 | 22.8 | 4 | 108 | 93 |
| Hornet 4 Drive | 21.4 | 6 | 258 | 110 |
| Hornet Sportabout | 18.7 | 8 | 360.0 | 175 |
| Valiant | 18.1 | 6 | 225.0 | 105 |
| Duster 360 | 14.3 | 8 | 360.0 | 245 |
Launch task schedualer within RStudio:
# Execute a system conmmand to launch task schedualer
system("control schedtasks")